import http from '@/utils/request'

import IBaseObj from '#/index'

const base = '/menu'

export const getMenuByPage = (app: string | number) =>
  http({
    url: `${base}/page/${app}`,
    method: 'get',
  })

export const getMenuList = () =>
  http(
    {
      url: `${base}/list`,
      method: 'get',
    },
    true
  )

export const getMenuTree = (data: IBaseObj) =>
  http({
    url: `${base}/tree`,
    method: 'post',
    data,
  })

const saveMenu = (data: IBaseObj) =>
  http({
    url: `${base}/save`,
    method: 'post',
    data,
  })

const delMenu = (id: string | number) =>
  http({
    url: `${base}/${id}`,
    method: 'delete',
  })

const getMenu = (id: string | number) =>
  http({
    url: `${base}/getMenu/${id}`,
    method: 'get',
  })
const grantMenu = (data: IBaseObj) =>
  http({
    url: `${base}/grantMenu`,
    method: 'post',
    data,
  })
const delUrl = `${base}`
const getUpperMenu = (app: string | number) =>
  http({
    url: `${base}/root/${app}`,
    method: 'get',
  })

export default {
  delUrl,
  getMenuByPage,
  saveMenu,
  delMenu,
  getMenu,
  grantMenu,
  getUpperMenu,
  getMenuList,
  getMenuTree,
}
